import React, { Component } from 'react'
import HomeHead from './home_head/home_head'
import Myswiper from '../../components/myswiper/myswiper'
import {baseUrl} from '../../api/base'
import {homehot} from '../../api/base'
import Homehot from './homehot/homehot'

 export default class Home extends Component{
     state={
         hot1:[],
         hot2:[]
     }
     componentDidMount(){
         this.newdata()
     }
     newdata=(cs)=>{
        fetch(baseUrl+homehot+'?city='+cs)
        .then(res=>res.json())
        .then(res=>{
            console.log(res.hot1)
            console.log(res)
            this.setState({
                hot1:res.hot1,
                hot2:res.hot2
            })
        })
        console.log(cs)
     }
     render(){
         console.log(this.state)
         return(
             <div>
                 {/* 头部 */}
                 <HomeHead newdata={this.newdata}/>
                 {/* 轮播图 */}
                 <Myswiper imgs={['http://iwenwiki.com/api/livable/banner/banner1.png','http://iwenwiki.com/api/livable/banner/banner2.png','http://iwenwiki.com/api/livable/banner/banner3.png']}/>
                 {/* 热点数据 */}
                 <Homehot title='热销单品' arr={this.state.hot1}/>
                 <Homehot title='家庭常用' arr={this.state.hot2}/>
             </div>
         )
     }
 }